﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;

namespace Skyhook.Resources
{
    internal class ResourceStorage
    {
        SortedDictionary<string, ResourceCollection> Collections = new SortedDictionary<string,ResourceCollection>();

        public static readonly ResourceStorage Instance = new ResourceStorage();

        private ResourceStorage()
        {
        }        

        public bool Contains<T>(string uid) where T : Resource
        {
            string typename = typeof(T).Name;

            if (!Collections.ContainsKey(typename))
            {
                return false;
            }

            return Collections[typename].Contains(uid);
        }

        public void Add<T>(T resource) where T : Resource
        {
            string typename = typeof(T).Name;

            if (!Collections.ContainsKey(typename))
            {
                Collections.Add(typename, new ResourceCollection());
            }

            Collections[typename].Add(resource);
        }

        public void Remove<T>(T resource) where T : Resource
        {
            string typename = typeof(T).Name;

            if (Collections.ContainsKey(typename))
            {
                Collections[typename].Remove(resource);
            }
        }

        public T Get<T>(string uid) where T : Resource
        {
            string typename = typeof(T).Name;

            return (T)(Collections[typename][uid]);
        }
    }
}
